/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.bean.custom;

import com.jb.framework.PersistentContext;
import com.jb.web.bean.Image;
import com.jb.web.bean.Table;
import com.jb.web.bean.TableCell;
import com.jb.web.bean.TextField;


public class Spinner extends Table {
    static final long serialVersionUID = 123123L;

    public void setDefault(PersistentContext pCtx) {
        setStyleClass("jbWindow");

        setRows(0);
        setColumns(2);
        setRows(2);

        setCellPadding(0);
        valueChanged(pCtx);
        getRow(0).setCols(2);
        getRow(0).valueChanged(pCtx);
        getRow(1).setCols(1);
        getRow(1).valueChanged(pCtx);

        TableCell cell_11 = getRow(0).getCellAt(0);
        cell_11.setRowSpan(2);

        TableCell cell_12 = getRow(0).getCellAt(1);

        TableCell cell_22 = getRow(1).getCellAt(0);
        cell_11.setStyleClass(null);
        cell_22.setStyleClass("jbSpinnerUp");
        cell_12.setStyleClass("jbSpinnerDn");

        TextField left = new TextField();

        Image imgLeft = new Image();

        Image imgRight = new Image();
        imgLeft.setBorderStyle(
            "border-top-style:outset;border-left-style:outset;border-right-style:outset;border-bottom-style:outset;border-top-width:2px;border-left-width:2px;border-right-width:2px;border-bottom-width:2px;border-top-color:white;border-left-color:white;border-right-color:white;border-bottom-color:white;");
        imgRight.setBorderStyle(
            "border-top-style:outset;border-left-style:outset;border-right-style:outset;border-bottom-style:outset;border-top-width:2px;border-left-width:2px;border-right-width:2px;border-bottom-width:2px;border-top-color:white;border-left-color:white;border-right-color:white;border-bottom-color:white;");
        imgLeft.setOnClick("$('" + left.getClientId() + "').value=$('" + left.getClientId() + "').value - 1+2");
        imgRight.setOnClick("$('" + left.getClientId() + "').value=$('" + left.getClientId() + "').value - 1");
        imgRight.setLocation("resources/images/palette/down-arrow.gif");
        imgLeft.setLocation("resources/images/palette/up-arrow.gif");

        imgLeft.setDestination("javascript:void(0);");
        imgRight.setDestination("javascript:void(0);");
        cell_11.addFacet(left.getId(), left);
        cell_12.addFacet(left.getId(), imgLeft);
        cell_22.addFacet(left.getId(), imgRight);
    }
}
